Skip to content

fix(android): hand drags to a scrollable that mounts after the sheet presents - #1024

Open
isaacrowntree wants to merge 2 commits into
lodev09:mainfrom
isaacrowntree:fix/android-late-scrollable-layout
Open

isaacrowntree wants to merge 2 commits into
lodev09:mainfrom
isaacrowntree:fix/android-late-scrollable-layout

Conversation

@isaacrowntree

Copy link
Copy Markdown
Contributor

Summary

On Android, a sheet with grabber={false} and dismissThreshold="short" does not close on a short pull when its scrollableRef scroll view mounts after the sheet has presented, for example content that shows a loader first and the list once it has loaded. The pull springs back, and only a pull long or fast enough for Material's own release rule closes the sheet.

BottomSheetBehavior looks for its nested scrolling child in onLayoutChild only. When the handle arrives, setScrollableHandle turns nested scrolling on for the scroll view, but nothing in that call lays the sheet out. On main a layout still follows most of the time, as a side effect: finalizeUpdates() runs setupGrabber(), which removes the grabber view and adds it back. With grabber={false} there is nothing to add, so no layout follows and the behavior never learns about the scroll view.

The behavior then drags the sheet itself. When it takes the gesture, the scroll view's cancelled touch stream stops its nested scroll while the sheet is still at the expanded offset, and Material's onStopNestedScroll sets the state back from STATE_DRAGGING. At the lift, wasDragging is false in TrueSheetBottomSheetBehavior.onTouchEvent, so releaseState (the short threshold) is skipped and Material's own rule decides.

Logged on main with temporary Log.d lines, one 15% pull:

onLayoutChild                                              (present)
setScrollableHandle handle=290 found=true                  (2 s later, no layout after it)
onStopNestedScroll nestedDragged=false state=1 top=74      (sheet still at the top)
lifted wasDragging=false state=2 top=399                   (settles back up)

With a grabber, or with this change, onLayoutChild follows setScrollableHandle within 10 ms and the same pull ends in onStopNestedScroll nestedDragged=true.

The fix requests a layout when the handle changes, which is what containerViewScrollViewDidChange already does for a remounted scroll view (#564). It is one call in TrueSheetView.setScrollableHandle, after the existing early return for an unchanged handle.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Test Plan

Repro branch, one commit on main that only touches the example: isaacrowntree/react-native-true-sheet@repro/android-late-scrollable. It adds a "Late Scrollable" sheet to the Standard screen and opens the bare example on that screen. The sheet has detents={[1]}, grabber={false}, dismissThreshold="short", and its ScrollView mounts 1.5 s after onDidPresent.

  1. yarn bare android, tap Late Scrollable, wait for the list.
  2. Pull the list down by about a quarter of the screen and let go.
  3. Expected: the sheet dismisses. On main: it springs back.

Measured on the bare example on an API 36 emulator (1080x2400). Each trial restarts the app, presents the sheet, waits 4 s, sends adb shell input swipe 540 500 540 <end> 400, and 2.5 s later checks with uiautomator dump whether "Item #1" is still on screen. Counts are trials where the sheet dismissed:

Pull (of screen height) main (da96a5d), grabber={false} This PR, grabber={false}
15% (360 px) 0 of 5 5 of 5
25% (600 px) 0 of 3 3 of 3
35% (840 px) 3 of 3 3 of 3

Control, the same sheet with the default grabber:

Pull main This PR
15% 5 of 5 8 of 9
25% 3 of 3 3 of 3
35% 3 of 3 3 of 3

The one miss with this PR ran right after a Gradle build, with the machine under heavy load. It did not come back in 6 more runs, and I did not find its cause.

Also ran yarn typecheck, eslint "**/*.{ts,tsx}", yarn test (175 passed) and ktlint on TrueSheetView.kt, and ./gradlew :app:assembleDebug for the bare example. Not tested on a physical device. The Android sources are unchanged between 4.1.0 and main.

Screenshots / Videos

None. The table above is from adb runs.

Checklist

  • I tested on iOS (no iOS change)
  • I tested on Android (API 36 emulator, bare example)
  • I tested on Web (no web change)
  • I updated the documentation (if needed)
  • I added a changelog entry (if needed)

🤖 Generated with Claude Code

https://claude.ai/code/session_01UdycNhpCYe25QHqrd5wdkQ

…presents

BottomSheetBehavior looks for its nested scrolling child in onLayoutChild
only. When scrollableRef's scroll view mounts after the sheet has presented
(content that shows a loader first), setScrollableHandle turns nested
scrolling on for it, but only a later layout tells the behavior about it.
Today that layout comes from finalizeUpdates() adding the grabber view back,
so with grabber={false} none follows.

The behavior then drags the sheet itself. The scroll view's cancelled touch
stream stops its nested scroll while the sheet is still at the expanded
offset, which sets the state back from DRAGGING, and the release skips the
dismissThreshold="short" rule: a short pull springs back.

Request a layout when the handle changes, as containerViewScrollViewDidChange
already does for a remounted scroll view.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UdycNhpCYe25QHqrd5wdkQ
@vercel

vercel Bot commented Nov 14, 2026

Copy link
Copy Markdown

@isaacrowntree is attempting to deploy a commit to the lodev09 Team on Vercel.

A member of the Team first needs to authorize it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UdycNhpCYe25QHqrd5wdkQ

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant